package com.anyisn.anyflickr.shell.controller
{
	import com.anyisn.anyflickr.common.events.PhotoLoadEvent;
	import com.anyisn.anyflickr.modules.PhotoInfo.PhotoInfoModule;
	import com.anyisn.anyflickr.shell.ShellFacade;
	import com.anyisn.anyflickr.shell.model.PhotoProxy;
	import com.anyisn.anyflickr.shell.view.PhotoInfoModuleMediator;
	import com.anyisn.puremvc.as3.multicore.utilities.pipes.event.ModuleEvents;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	public class PhotoInfoWindowOpenCommand extends SimpleCommand
	{
		override public function execute(notification:INotification) : void {
			var photoP:PhotoProxy = facade.retrieveProxy(PhotoProxy.NAME) as PhotoProxy;
			var e:PhotoLoadEvent = notification.getBody() as PhotoLoadEvent;
			if(photoP.hasPIWin) {
				sendNotification(ShellFacade.CHANGE_PHOTO_IN_PHOTO_INFO_WINDOW, [e.bitmap, e.photo]);
			} else {
				var pi:PhotoInfoModule = new PhotoInfoModule(e.bitmap, e.photo);
				photoP.hasPIWin = true;
				sendNotification(ModuleEvents.CONNECT_MODULE_JUNCTION, pi);
				facade.registerMediator(new PhotoInfoModuleMediator(pi));
			}
		}
	}
}